#include  <algorithm>
#include  <iostream>
#include  <vector>
#include  <iterator>
using namespace std;

struct node
{
	char name[51];
	short mark;
};

bool cmp(struct node *a, struct node *b)
{
	return a->mark > b->mark;
}

int main(int argc, char *argv[])
{
	int n;

	while( cin >> n )
	{
		vector<struct node*> a,b;
		struct node* p;
		bool err = false, notstable = false;

		for( int i = 0 ; i < n ; ++i )
		{
			p = new struct node;
			cin >> p->name >> p->mark;
			a.push_back(p);
		}
		for( int i = 0 ; i < n ; ++i )
		{
			p = new struct node;
			cin >> p->name >> p->mark;
			b.push_back(p);
		}

		for( int i = 0 ; i < n-1 ; ++i )
		{
			if(b[i]->mark < b[i+1]->mark)
			{
				cout << "Error" << endl;
				err = true;
				break;
			}
		}
		
		stable_sort(a.begin(),a.end(),cmp);

		if( !err )
		{
			for( int i = 0 ; i < n ; ++i )
			{
				if( strcmp(a[i]->name,b[i]->name) != 0)
				{
					notstable = true;
					cout << "Not Stable" << endl;
					break;
				}
			}
		}
		
		if( err || notstable )
		{
			for( int i = 0 ; i < n ; ++i )
			{
				cout << a[i]->name << " " << a[i]->mark << endl;
			}
			
		}
		else
			cout << "Right" << endl;

		for( int i = 0 ; i < n ; ++i )
		{
			delete a[i];
			delete b[i];
		}
		
	}
}
